package com.whj.servicemap.service.impl;

import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.request.TraceTimeRequest;
import com.whj.internalcommon.response.TerminalResponse;
import com.whj.internalcommon.response.TrsearchResponse;
import com.whj.servicemap.remote.TerminalClient;
import com.whj.servicemap.service.TerminalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/16 - 01 - 16 - 17:28 
 * @Description: com.whj.servicemap.service.impl
 */

@Service
public class TerminalServiceImpl implements TerminalService {

    @Autowired
    private TerminalClient terminalClient;

    /**
     * 根据名字来创建终端
     *
     * @param name
     * @param desc 车辆的id
     * @return 终端id
     */
    public ResponseResult add(String name, String desc) {

        return terminalClient.add(name, desc);
    }

    /**
     * 根据圆心半径搜索设备，并返回实时位置。
     *
     * @param center 中心点
     * @param radius 半径
     * @return
     */
    @Override
    public ResponseResult<List<TerminalResponse>> aroundSearch(String center, Integer radius) {
        return terminalClient.aroundSearch(center, radius);
    }

    /**
     * 根据传来的 tid 和 起始时间和中止时间 计算路程和时间
     *
     * @param traceTimeRequest
     * @return
     */
    @Override
    public ResponseResult<TrsearchResponse> trsearch(TraceTimeRequest traceTimeRequest) {
        String tid = traceTimeRequest.getTid();
        Long startTime = traceTimeRequest.getStartTime();
        Long endTime = traceTimeRequest.getEndTime();
        return terminalClient.traceSearch(tid, startTime, endTime);
    }
}
